<template>
  <div class="download">
    <van-swipe :autoplay="3000" :show-indicators="false" :touchable="true" :loop="true">
      <van-swipe-item v-for="(item, index) in banner" :key="index">
        <img class="download_bg" :src="$img(item)">
      </van-swipe-item>
    </van-swipe>
    <a id="download-app" @click="download">点击下载</a>
  </div>
</template>

<script>
export default {
  data () {
    return {
      is_wechat: null,
      data: {},
      url: '',
      banner: ['download_bg1.png', 'download_bg2.png']
    }
  },
  methods: {
    download () {
      if (this.$isWxBrowser()) {
        this.$dialog({ message: '请使用外部浏览器访问下载' })
        return
      }
      var a = document.createElement('a')
      var url = this.url
      var filename = 'zhanye.apk'
      a.href = url
      a.download = filename
      a.click()
      window.URL.revokeObjextURL(url)
    },
    getDownloadUrl () {
      this.$axios.get('/api/public/apk_download_uri').then(res => {
        if (res.status === 200) {
          this.url = res.data.uri
        }
      })
    }
  },
  created () {
    this.getDownloadUrl()
  }
}
</script>

<style lang="scss">
@import './style.scss';
.download{
  overflow: hidden;
  height: 100%;
  .van-swipe{
    overflow: hidden;
    height: 100%;
    width: 100%;
  }
  .download_bg{
    width: 100%;
  }
}
</style>
